package com.itguigu.ioc_03;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

@Controller
public class UserController {

    /**
     * 如果使用xml方式di 还需要为属性UserService 写set方法
     * <bean id="userService" class="com.atguigu.ioc_03.UserServiceImpl"/>
     *
     * <bean id="userController" class="com.atguigu.ioc_03.UserController">
     *   <property name="userService" ref="userService"/>
     * </bean>
     */
    /*
    相当于<property name="userService" ref="userService"/>
    但是此时双方都要注册进ioc容器中
    @Autowired 首先进行ByType注入，如果找不到，需要使用@Qualifier(name="userService") 再进行ByName注入
    @Qualifier 必须要和 @Autowired一起使用
    */
    @Autowired
    @Qualifier(value = "newUserServiceImpl")
    private UserService userService;

    /**
     *  @Resource(name = "newUserServiceImpl") //java EE规范
     *  ==
     * @Atuowired + @Qualifier
     *
     * 首先进行ByName注入，如果找不到，再进行ByType注入
     *
     */
    @Resource(name = "newUserServiceImpl")
    private UserService userService2;

    public void show() {

        String show = userService2.show();
        System.out.println(show);

    }


}
